import 'package:flutter_test/flutter_test.dart';
import 'package:open_file_ohos/open_file_ohos.dart';
import 'package:open_file_ohos/src/common/parse_args.dart';

void main() {
  test('default constructor should initialize with default values', () {
    final result = OpenResult();
    expect(result.type, equals(ResultType.done));
    expect(result.message, equals('done'));
  });

  test('fromJson should correctly parse JSON', () {
    final json = {
      'type': -1,
      'message': 'No app to open this file'
    };
    final result = OpenResult.fromJson(json);
    expect(result.type, equals(ResultType.noAppToOpen));
    expect(result.message, equals('No app to open this file'));
  });

  test('fromJson should handle invalid types gracefully', () {
    final json = {'type': 999, 'message': 'Unknown error'};
    final result = OpenResult.fromJson(json);
    expect(result.type, equals(ResultType.done)); // Fallback to done for unknown types
    expect(result.message, equals('Unknown error'));
  });

  test('should escape spaces, parentheses, and single quotes', () {
    final args = ['hello world', '(hello)', "it's", 'a nice day'];
    final result = parseArgs(args);
    expect(result, equals('hello\\ world \\(hello\\) it\\\'s a\\ nice\\ day'));
  });

  test('should handle single argument without special characters', () {
    final args = ['simple'];
    final result = parseArgs(args);
    expect(result, equals('simple'));
  });

  test('should handle multiple arguments without special characters', () {
    final args = ['one', 'two', 'three'];
    final result = parseArgs(args);
    expect(result, equals('one two three'));
  });
}
